//
//  LoginStackView.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/4/12.
//

import SwiftUI
import FlowStacks

enum LoginStack: Hashable {
    case loginPwd
    case forgetPwd
    case loginSms
    case register
    case verificationCode(account: String, type: RequestCodeType, verifyType: ValidateCodeType)
    case setPwd(account: String, isRegister: Bool)
    case webPage(url: String)
}

struct LoginStackView: View {
    @State private var routes: [Route<LoginStack>] = [.init(screen: .loginPwd, style: .push)]

    var body: some View {
        FlowStack($routes, withNavigation: true) {
            // 空视图作为入口，其实会自动展示 routes[0] 的 screen
            LoginPwdView()
    
            .flowDestination(for: LoginStack.self) { stack in
                switch stack {
                    case .loginPwd:
                        LoginPwdView().navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                    case .forgetPwd:
                        ForgetPwdView().navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                    case .loginSms:
                        LoginSMSView().navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                    case .register:
                        RegisterView().navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                    case let .verificationCode(account, type, verifyType):
                        let verifyVM = VerificationCodeViewModel(account: account, type: type, verifyType: verifyType)
                        VerificationCodeView(viewModel: verifyVM).navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                    case let .setPwd(account, isRegister):
                        let setPwdVM = SetPwdViewModel(account: account, isRegister: isRegister)
                        SetPwdView(viewModel: setPwdVM).navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                    case let .webPage(url):
                        WebPageView(url: url).navigationBarHidden(true).enableSwipeBackGesture(enable: true)
                }
            }
        }
    }
}
